package Engine.UIControl
{
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import Engine.UIControl.UIMouse;
	
	public class MouseIcon extends IconBase
	{
		private static var ins:MouseIcon = null;
		private var _parentIcon:IconBase = null;
		private var _isDraging:Boolean = false;
		
		public static function getInstance(p_content:Sprite=null,width:Number = 42,height:Number = 42):MouseIcon
		{
			if(ins == null)
				ins = new MouseIcon(p_content,width,height);
			return ins;
		}
		
		public function MouseIcon(p_content:Sprite=null,width:Number = 42,height:Number = 42)
		{
			super(p_content,width,height);
		}
		
		public function onStartDrag(stageX:Number,stageY:Number):void
		{
			this.x = stageX - this.width/2;
			this.y = stageY - this.height/2;
			this._content.scaleX = 1.2;
			this._content.scaleY = 1.2;
			this._content.startDrag();
			this._isDraging = true;
			UIMouse.hide();
		}
		
		public function setParentIcon(icon:IconBase):void
		{
			this._parentIcon = icon;
		}
		
		override protected function onMouseDown(event:MouseEvent):void
		{
			
		}
		
		override protected function onMouseUp(event:MouseEvent):void
		{
			
		}
		
		override protected function onMouseIn(event:MouseEvent):void
		{
			
		}
		
		override protected function onMouseOut(event:MouseEvent):void
		{
			
		}
		
		override protected function onMouseClick(event:MouseEvent):void
		{
			if(this._isDraging)
			{
				this._isDraging = false;
				this._content.scaleX = 1.0;
				this._content.scaleY = 1.0;
				this._content.stopDrag();
				this._parentIcon.onDropEvent(this._content.dropTarget);
				this.removeIconBMP();
				this._content.parent.removeChild(this._content);
				this._parentIcon = null;
				UIMouse.show();
			}
		}
	}
}